package com.pattern.once.proxy.d;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class P1 <T> implements InvocationHandler {

    T tagter;

    public P1(T tagter) {
        this.tagter = tagter;
    }

    public <T> T newInstance(Class c){
        T o = (T) Proxy.newProxyInstance(c.getClassLoader(), new Class[]{c}, this);
        return o;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("方法执行前");
        Object invoke = method.invoke(tagter, args);
        System.out.println("方法执行后");
        return invoke;
    }
}
